#ifndef SURFACEGLWIDGET_H
#define SURFACEGLWIDGET_H

#include <QMatrix4x4>
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLWidget>

class SurfaceGLWidget : public QOpenGLWidget, protected QOpenGLFunctions {
    Q_OBJECT

public:
    explicit SurfaceGLWidget(QWidget *parent = nullptr);
    ~SurfaceGLWidget();

protected:
    void initializeGL() override;
    void paintGL() override;
    void resizeGL(int w, int h) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

private:
    void initShaders();
    void initSurfaceData();
    void updateSurfaceData();

    QOpenGLShaderProgram    *m_program;
    QOpenGLBuffer            m_vbo;
    QOpenGLVertexArrayObject m_vao;

    QMatrix4x4 m_projection;
    QMatrix4x4 m_view;
    QMatrix4x4 m_model;

    QPoint m_lastPos;
    float  m_xRot;
    float  m_yRot;
    float  m_zRot;
    float  m_scale;

    static const int SURFACE_POINTS = 100;
    QVector<GLfloat> m_vertices;
    QVector<GLfloat> m_colors;
};

#endif  // SURFACEGLWIDGET_H
